package com.lenovo.lcdm.team.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lenovo.lcdm.common.exception.BusinessException;
import com.lenovo.lcdm.team.dto.UserAuthDto;
import com.lenovo.lcdm.team.dto.UserDto;
import com.lenovo.lcdm.team.dto.UserPwdDto;
import com.lenovo.lcdm.team.dto.UserQueryDto;
import com.lenovo.lcdm.team.entity.TeamUser;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lenovo.lcdm.team.vo.GroupVo;

import java.util.List;

/**
 * @author sunby1
 * @description 针对表【plm_user】的数据库操作Service
 * @createDate 2023-12-21 17:55:12
 */
public interface ITeamUserService extends IService<TeamUser> {

    /**
     * 分页查询user列表
     *
     * @param page
     * @param userDto
     * @return
     */
    List<TeamUser> listByPage(Page page, UserQueryDto userDto);

    /**
     * 创建/更新用户并分配group
     *
     * @param userDto
     */
    void saveUser(UserDto userDto) throws BusinessException;

    /**
     * 查找用户
     *
     * @param id
     * @return
     * @throws Exception
     */
    UserDto getUserInfo(Long id) throws Exception;

    /**
     * 删除用户及用户的group关系
     *
     * @param itCode
     * @throws Exception
     */
    void deleteUser(String itCode) throws Exception;

    /**
     * 获取用户所有group及role
     *
     * @param itCode
     * @param hasRole - 是否查询角色
     * @return
     */
    UserAuthDto getUserAuthorities(String itCode, boolean hasRole);

    /**
     * 查询当前登录用户的基本信息
     * @return
     * @throws Exception
     */
    TeamUser getCurrentUser();

    /**
     * 查询用户的group name及group desc,如果用户不存在返回空
     * @param itCode
     * @return
     */
    List<GroupVo> getUserGroups(String itCode);

    /**
     * 如果itCode对应的userName为空或有变更，则更新userName
     * @param itCode
     * @param userName
     * @return
     */
    boolean updateUserName(String itCode, String userName);

    /**
     * 更新最后登陆时间
     * @param itCode
     */
    boolean updateLastLoginTime(String itCode);

    /**
     * 修改/重置密码
     * @param userPwdDto
     * @return
     */
    boolean modifyPwd(UserPwdDto userPwdDto, boolean isResetPwd);


}
